import button from '@/const/button';

import requestUrl from '@/const/requestUrl';

// 按钮顺序表
const orderMap = {
  add: 0,
  edit: 1,
  check: 2,
  delete: 3,
  upload: 4,
  download: 5,
  copy: 6,
};

const getOrderKey = (order) => orderMap[order.name] ?? 100;

const setOrder = (constMap) => {
  Object.keys(constMap).forEach((key) => {
    constMap[key].sort((a, b) => getOrderKey(a) - getOrderKey(b));
  });
};

// 所有按钮map
const buttonMap = {
  ...button,
};

setOrder(buttonMap);

export { buttonMap };

// 所有按钮map
export const requestUrlMap = {
  ...requestUrl,
};

// 通过key获取对应的按钮组
export const getButtonListFn = (key) => {
  if (!key) return [];
  return buttonMap[key] || [];
};

export const getRequestUrlListFn = (key) => {
  if (!key) return [];
  return requestUrlMap[key] || [];
};

// 通过key获取对应的按钮组的name
// export const getButtonNamesByKey = (key) => {
//   return getButtonsByKey(key).map((item) => item.name);
// };
